package com.pro01.backend.mapper;

import com.pro01.backend.pojo.ForumPostLike;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ForumPostLikeMapper {

    // 点赞
    @Insert("""
        INSERT INTO forum_post_likes (user_id, post_id, created_at)
        VALUES (#{userId}, #{postId}, NOW())
    """)
    int insertLike(@Param("userId") Long userId, @Param("postId") Long postId);

    @Select("""
        SELECT COUNT(*) FROM forum_post_likes
        WHERE user_id = #{userId} AND post_id = #{postId}
    """)
    int hasLiked(@Param("userId") Long userId, @Param("postId") Long postId);

    // 取消点赞
    @Delete("""
    DELETE FROM forum_post_likes
    WHERE user_id = #{userId} AND post_id = #{postId}
""")
    int deleteLike(@Param("userId") Long userId, @Param("postId") Long postId);

    // 查询当前用户点赞过的帖子ID列表
    @Select("""
    SELECT post_id
    FROM forum_post_likes
    WHERE user_id = #{userId}
      AND post_id IN (${postIds})
""")
    List<Long> getLikedPostIds(@Param("userId") Long userId, @Param("postIds") String postIds);

}
